﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using DotNetNuke;
using DotNetNuke.Entities;
using DotNetNuke.Entities.Content;
using DotNetNuke.Common.Utilities;

namespace Ivevane.Modules.Newslider.Components
{
    public class Article:ContentItem
    {
        public int ItemId { get; set; }

        public int ModuleId { get; set; }

        public int ContentItemId { get; set; }

        public DateTime CreatedDate { get; set; }

        public string Title { get; set; }

        public string URL { get; set; }

        public DateTime ExpireDate { get; set; }

        public string Description { get; set; }

        public int ViewOrder { get; set; }

        public int CreatedByUserId { get; set; }

        public DateTime PublishDate { get; set; }

        public string ImageSource { get; set; }

        public int PortalId { get; set; }

        // Read Only Properties
        ///<summary>
        ///The username of the user who created the article
        ///</summary>
        ///
        public string CreatedByUsername
        {
            get
            {
                return CreatedByUserId != 0 ? DotNetNuke.Entities.Users.UserController.GetUserById(PortalId, CreatedByUserId).Username : Null.NullString;
            }
        }

        #region IHydratable Implementation
        ///<summary>
        ///
        ///</summary>
        ///<param name="dr"></param>
        public override void Fill(System.Data.IDataReader dr)
        {
            // Call the base classes fill method to populate base class properties
            base.FillInternal(dr);

            ItemId = Null.SetNullInteger(dr["ItemId"]);
            ModuleId = Null.SetNullInteger(dr["ModuleId"]);
            ContentItemId = Null.SetNullInteger(dr["ContentItemId"]);
            CreatedDate = Null.SetNullDateTime(dr["CreatedDate"]);
            Title = Null.SetNullString(dr["Title"]);
            URL = Null.SetNullString(dr["URL"]);
            ExpireDate = Null.SetNullDateTime(dr["ExpireDate"]);
            Description = Null.SetNullString(dr["Description"]);
            ViewOrder = Null.SetNullInteger(dr["ViewOrder"]);
            CreatedByUserId = Null.SetNullInteger(dr["CreatedByUserId"]);
            PublishDate = Null.SetNullDateTime(dr["PublishDate"]);
            ImageSource = Null.SetNullString(dr["ImageSource"]);

        }

        /// <summary>
        /// Gets and sets the Key Id
        /// </summary>
        /// <returns>An Integer</returns>
        public override int KeyID
        {
            get
            {
                return ItemId;
            }
            set
            {
                ItemId = value;
            }
        }


        #endregion
    }
}